//
//  DSZGZDRViewController.m
//  7.13苏宁框架
//
//  Created by app15 on 15/7/21.
//  Copyright (c) 2015年 lovena. All rights reserved.
//

#import "DSZGZDRViewController.h"
#import "DSZShowViewController.h"
#import "DSZGZDRTableViewCell.h"
#import "DSZTJGroupModel.h"
#import "UIImageView+WebCache.h"
#import "DSZGZXQViewController.h"
#import "DSZGZDRview.h"
#import "DSZTJSuperModel.h"
NSArray *groupModelArray;
DSZTJSuperModel *DRmodel;
@interface DSZGZDRViewController ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation DSZGZDRViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadNa];
    //_tableView.frame=CGRectMake(0, 0, 320, 480);
    _tableView.delegate=self;
    _tableView.dataSource=self;
    _tableView.separatorStyle=0;
    [self.view addSubview:_tableView];
    // Do any additional setup after loading the view from its nib.
}
-(void)viewWillAppear:(BOOL)animated{
    DSZShowViewController *view=(DSZShowViewController*)self.tabBarController;
    [view hiddenShowTabbar:YES];
}

-(NSArray*)Drgroupmode:(NSArray*)array model:(DSZTJSuperModel*)model{
    groupModelArray=array;
    DRmodel=model;
    return groupModelArray;
}
-(void)loadNa{
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, 44)];
    UIButton *button=[UIButton buttonWithType:UIButtonTypeSystem];
    button=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 25, 40)];
    [button setImage:[UIImage imageNamed:@"back_black_icon"]  forState:UIControlStateNormal];
    [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:button];
    UIBarButtonItem *barbutton=[[UIBarButtonItem alloc]initWithCustomView:view];
    self.navigationItem.leftBarButtonItem=barbutton;
    
}

-(void)back{
    DSZShowViewController *view=(DSZShowViewController*)self.tabBarController;
    [view hiddenShowTabbar:NO];
    [self.navigationController popViewControllerAnimated:YES];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    //NSLog(@"%i",groupModelArray.count);
    return groupModelArray.count;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *IDS=@"cell";
    DSZGZDRTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:IDS];
    if (cell==nil) {
        cell=[[DSZGZDRTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:IDS];
    }
    DSZTJGroupModel *model=groupModelArray[indexPath.row];
    [cell.groupImageView setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",model.image]]];
    NSInteger i=model.name.length;
    cell.groupNameLabel.frame=CGRectMake(cell.groupNameLabel.frame.origin.x, cell.groupNameLabel.frame.origin.y, i*15, cell.groupNameLabel.frame.size.height);
    cell.vipimage.frame=CGRectMake(cell.groupNameLabel.frame.origin.x+i*15+10, cell.vipimage.frame.origin.y, 12, 12);

    cell.groupNameLabel.text=model.name;
    cell.groupintorLabel.text=model.intor;
    cell.selectionStyle=0;
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    DSZGZXQViewController *view=[[DSZGZXQViewController alloc]init];
    DSZTJGroupModel *model=groupModelArray[indexPath.row];
    [view XqGroupModel:model];
//    if ([self.delegate respondsToSelector:@selector(detailView)]) {
//        [_delegate detailView];
//    }
    [self.navigationController pushViewController:view animated:NO];
    
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    DSZGZDRview *vi=[DSZGZDRview viewnib];
    vi.superName.text=DRmodel.title;
    vi.frame=CGRectMake(0, 0, 320, 30);
    
    return vi;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 30;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
